
// promise形式的getSetting
export const getSetting = () => {
  return new Promise((resolve, reject) => {
    wx.getSetting({
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => { }
    });

  })
}

export const chooseAddress = () => {
  return new Promise((resolve, reject) => {
    wx.chooseAddress({
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => { }
    });

  })
}

export const openSetting = () => {
  return new Promise((resolve, reject) => {
    wx.openSetting({
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => { }
    });

  })
}


export const showModal = (params) => {

  return new Promise((resolve, reject) => {
    wx.showModal({
      title: params.title || "提示",
      content: params.content,
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      }
    })
  })
}




export const showToast = (params) => {

  return new Promise((resolve, reject) => {
    wx.showToast({
      title: params.title || "请检查",
      icon: params.icon || 'none',
      image: '',
      duration: 1500,
      mask: false,
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => { }
    });
  })
}



export const login = () => {

  return new Promise((resolve, reject) => {
    wx.login({
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      }
    });
  })
} 



export const requestPayment = (pay) => {

  return new Promise((resolve, reject) => {
    wx.requestPayment({
      // timeStamp: '1565346079',
      // nonceStr: 'U6tYjNdYvm3ReKgI',
      // package: 'wx09182118356902a15c8b8d071931343000',
      // signType: 'MD5',
      // paySign: 'C514E29387794F84004C983AFFF4707F',
      ...pay,
      success: (result) => {
        resolve(result)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => {}
    });
      
  })
} 